<?php


namespace app\controller\api\common;

use app\common\repositories\system\merchant\ArticleRepository as repository;
use app\common\repositories\user\UserVisitRepository;
use crmeb\basic\BaseController;
use crmeb\services\SwooleTaskService;
use think\App;

class MerchantArticle extends BaseController
{

    /**
     * @var repository
     */
    protected $repository;

    /**
     * StoreBrand constructor.
     * @param App $app
     * @param repository $repository
     */
    public function __construct(App $app, repository $repository)
    {
        parent::__construct($app);
        $this->repository = $repository;
    }
    /**
     * @param ArticleRepository $repository
     * @return mixed
     * @author: fupeng
     * @day: 2023/11/29
     */
    public function lst()
    {
        $where = $this->request->params(['cid']);
        $where['status'] = 1;
        [$page, $limit] = $this->getPage();
        return app('json')->success($this->repository->getApiList($where, $page, $limit,'sort desc','mer_article_id,title,image_input,synopsis,create_time'));
    }

    /**
     * @param $id
     * @return mixed
     * @author: fupeng
     * @day: 2023/11/30
     */
    public function detail($id)
    {
        if (!$this->repository->ApiExists($id))
            return app('json')->fail('文章不存在');
        $data = $this->repository->get($id,0);
        return app('json')->success($data);
    }
}
